package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;

import java.time.Duration;

public class FluxConcatWithMergeExample {
    public static void main(String[] args) throws InterruptedException {
        Flux<Integer> flux1 = Flux.just(1, 2, 3).delayElements(Duration.ofMillis(100));
        Flux<Integer> flux2 = Flux.just(4, 5, 6).delayElements(Duration.ofMillis(50));
        Flux<Integer> flux3 = Flux.just(7, 8, 9).delayElements(Duration.ofMillis(75));

        // 使用 concatWith 方法，按顺序执行
        flux1.concatWith(flux2)
                .concatWith(flux3)
                .subscribe(v ->{
                    System.out.println("concatWith = " + v);
                });

        // 使用 merge 方法，并发执行
        Flux.merge(flux1, flux2, flux3)
                .subscribe(v ->{
                    System.out.println("merge = " + v);
                });

        Thread.sleep(22333);
    }
}

